package com.fkg.test.mvp.view;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.fkg.test.R;
import com.fkg.test.mvp.presenter.LoginPresenterCompl;

public class LoginActivity extends AppCompatActivity implements ILoginView, View.OnClickListener {

    EditText et_name;
    EditText et_password;
    Button btn_affirm;
    Button btn_clear;

    LoginPresenterCompl iLoginPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mvp);

        et_name = (EditText) findViewById(R.id.et_name);
        et_password = (EditText) findViewById(R.id.et_password);
        btn_affirm = (Button) findViewById(R.id.btn_affirm);
        btn_clear = (Button) findViewById(R.id.btn_clear);

        btn_affirm.setOnClickListener(this);
        btn_clear.setOnClickListener(this);

        iLoginPresenter = new LoginPresenterCompl(this);
    }

    @Override
    public void onClearText() {

        et_name.setText("");
        et_password.setText("");
        Toast.makeText(this, "清除成功", Toast.LENGTH_SHORT).show();

    }

    @Override
    public void onLoginResult(Boolean result, int code) {

        btn_affirm.setEnabled(true);
        btn_clear.setEnabled(true);

        if (result) {
            Toast.makeText(this, "登录成功", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(this, "登录失败", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_affirm:
                iLoginPresenter.doLogin(et_name.getText().toString().trim(), et_password.getText().toString().trim());
                break;
            case R.id.btn_clear:
                iLoginPresenter.clear();
                break;
        }
    }



    /*@BindView(R.id.et_name)
    EditText et_name;
    @BindView(R.id.et_password)
    EditText et_password;
    @BindView(R.id.btn_affirm)
    Button btn_affirm;

    @BindView(R.id.btn_clear)
    Button btn_clear;

    LoginPresenterCompl iLoginPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mvp_login);

        iLoginPresenter = new LoginPresenterCompl(this);
    }

    @Override
    public void onClearText() {

        et_name.setText("");
        et_password.setText("");
        Toast.makeText(this,"清除成功",Toast.LENGTH_SHORT).show();

    }

    @Override
    public void onLoginResult(Boolean result, int code) {

        btn_affirm.setEnabled(true);
        btn_clear.setEnabled(true);

        if (result){
            Toast.makeText(this,"登录成功",Toast.LENGTH_SHORT).show();
        }else {
            Toast.makeText(this,"登录失败",Toast.LENGTH_SHORT).show();
        }
    }

    @OnClick(R.id.btn_affirm)
    public void Affirm(){
        iLoginPresenter.doLogin(et_name.getText().toString().trim(),et_password.getText().toString().trim());
    }

    @OnClick(R.id.btn_clear)
    public void Clear(){
        iLoginPresenter.clear();
    }*/
}
